package com.engine.cese.duss.srm.pricebidhall.web;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.cese.duss.srm.util.Base64Util;
import com.engine.cese.duss.srm.util.CalUtil;
import com.engine.cese.duss.srm.util.GenUtil;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.*;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2021-03-09
 * @Description: 竞价大厅
 * @ModifyLog:
 **/

public class WeaPriceBidHallAction {

    /**
     * @Description: 根据采购立项单获取竞价立项信息
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getJjcglxdData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getJjcglxdData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                String sql = "select cglxd,cglxmc,jjkssj,slcjsj,jjlx,jjzsc,zdcjcs,csjjyc,jjjzj,fdy,fd,lxsqr,jjgc,zdtbdws from (\n" +
                        "select cglxd,cglxmc,concat(jjkssj,':00') as jjkssj,slcjsj,jjlx,\n" +
                        "jjzsc,zdcjcs,csjjyc,jjjzj,fdy,fd,lxsqr,jjgc,zdtbdws from uf_jjgz where cglxd =? order by id desc) " +
                        "where rownum<2";
                rs.executeQuery( sql, cglxd );
                rs.next();
                String cglxmc = Util.null2String( rs.getString( "cglxmc" ) );//采购立项单名称
                String jjkssj = Util.null2String( rs.getString( "jjkssj" ) );//竞价开始时间
                String slcjsj = Util.null2String( rs.getString( "slcjsj" ) );//首轮出价时间
                String jjlx = Util.null2String( rs.getString( "jjlx" ) );//竞价类型
                String jjlxmc = GenUtil.getSelectItem( 1134, "jjlx", jjlx );
                String jjzsc = Util.null2String( rs.getString( "jjzsc" ) );//竞价延时长
                String zdcjcs = Util.null2String( rs.getString( "zdcjcs" ) );//最大出价次数
                String csjjycid = Util.null2String( rs.getString( "csjjyc" ) );//超时竞价延迟
                String csjjyc = GenUtil.getSelectItem( 1134, "csjjyc", csjjycid );
                String jjjzj = Util.null2String( rs.getString( "jjjzj" ) );//竞价基准价
                String fdy = Util.null2String( rs.getString( "fdy" ) );//幅度（元）
                String fdf = Util.null2String( rs.getString( "fd" ) );//幅度%
                String fd = !"".equals( fdy ) ? fdy + "(元)" : fdf + "%";
                String zdbj = !"".equals( fdy ) ? fdy : CalUtil.fMultiply( CalUtil.fDivide( fdf, "100" ), jjjzj );
                String lxsqr = Util.null2String( rs.getString( "lxsqr" ) );//立项申请人
                String jjgc = Util.null2String( rs.getString( "jjgc" ) );//竞价过程
                String zdtbdws = Util.null2String( rs.getString( "zdtbdws" ) );//中标人个数
                String gkjjgs = "0".equals( jjgc ) ? "是" : "否";
                String gkjjjg = "1".equals( jjgc ) ? "是" : "否";
                datas.put( "cglxmc", cglxmc );
                datas.put( "jjkssj", jjkssj );
                datas.put( "slcjsj", slcjsj );
                datas.put( "jjlx", jjlx );
                datas.put( "jjlxmc", jjlxmc );
                datas.put( "jjzsc", jjzsc );
                datas.put( "zdcjcs", zdcjcs );
                datas.put( "csjjyc", csjjyc );
                datas.put( "jjjzj", jjjzj );
                datas.put( "fd", fd );
                datas.put( "zdbj", zdbj );
                datas.put( "lxsqr", lxsqr );
                datas.put( "jjgc", jjgc );
                datas.put( "gkjjgs", gkjjgs );
                datas.put( "gkjjjg", gkjjjg );
                datas.put( "zdtbdws", zdtbdws );
                apidatas.put( "datas", datas );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 插入供应商报销信息到报价信息表中
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/insertGysbjInfo")
    @Produces({MediaType.TEXT_PLAIN})
    public String insertGysbjInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                User user = HrmUserVarify.getUser( request, response );
                String loginid = user.getLoginid();
                String sql = "select gysmc,jmgysmc,dh,jmdh from uf_bidguestinfo where cglxd=? and gysid=?";
                rs.executeQuery( sql, cglxd, loginid );
                rs.next();
                String gysmc = Util.null2String( rs.getString( "gysmc" ) );//供应商名称
                String jmgysmc = Util.null2String( rs.getString( "jmgysmc" ) );//加密供应商名称
                String dh = Util.null2String( rs.getString( "dh" ) );//代号
                String jmdh = Util.null2String( rs.getString( "jmdh" ) );//加密代号
                String bj = Util.null2String( request.getParameter( "bj" ) );//报价
                String jmbj = "******";//加密报价
                String fd = Util.null2String( request.getParameter( "fd" ) );//幅度
                int fdsz = Util.getIntValue( GenUtil.getNumbers( fd ) );//幅度数字
                String jmfd = "******";//加密幅度
                String rqsj = DateUtil.getFullDate();//日期时间
                int ccbj = 0;
                String jmccbj = "******";
                String sql1 = "select ccbj from uf_bjxxb where cglxd=? and gysid=? group by gysid,dh,ccbj";
                rs.executeQuery( sql1, cglxd, loginid );
                if (rs.next()) {
                    ccbj = Util.getIntValue( rs.getString( "ccbj" ) );//初次报价
                } else {
                    ccbj = Util.getIntValue( GenUtil.getNumbers( bj ) );
                }
                String sql2 = "insert into uf_bjxxb(cglxd,gysid,gysmc,jmgysmc,dh,jmdh,bj,jmbj,ccbj,jmccbj,fd,fdsz,jmfd,rqsj)\n" +
                        "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                Object[] params = {cglxd, loginid, gysmc, jmgysmc, dh, jmdh, bj, jmbj, ccbj, jmccbj, fd, fdsz, jmfd, rqsj};
                rs.executeUpdate( sql2, params );
                apidatas.put( "api_status", true );
            }

        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 更新供应商报价次数到报价信息中
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/updateGysBjTimes")
    @Produces({MediaType.TEXT_PLAIN})
    public String updateGysBjTimes(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                User user = HrmUserVarify.getUser( request, response );
                String loginid = user.getLoginid();
                String zxbj = Util.null2String( request.getParameter( "zxbj" ) );//最新报价
                int zdcscs = Util.getIntValue( request.getParameter( "zdcscs" ) );//最大出手次数
                String rqsj = DateUtil.getFullDate();//时间
                int bjcs = GenUtil.getGysBjCounts( cglxd, loginid );
                int sycs = zdcscs - bjcs;
                String sql = "update uf_bidguestinfo set bjcs=?,zxbj=?,zdcscs=?,sycs=?,rqsj=? where cglxd=? and gysid=?";
                Object[] params = {bjcs, zxbj, zdcscs, sycs, rqsj, cglxd, loginid};
                rs.executeUpdate( sql, params );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据首轮报价时间更新供应商报价次数到报价信息中
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/updateFirTimes")
    @Produces({MediaType.TEXT_PLAIN})
    public String updateFirTimes(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                String staTime = Util.null2String( request.getParameter( "staTime" ) );//竞价立即开始时间
                String firTime = Util.null2String( request.getParameter( "firTime" ) );//首轮报价时间
                int zdcscs = Util.getIntValue( request.getParameter( "zdcscs" ) );//最大出手次数
                String sql = "select wm_concat(gysid) from (\n" +
                        "select gysid from uf_bjxxb where cglxd=? and rqsj " +
                        "between ? and ? group by gysid)";
                rs.executeQuery( sql, cglxd, staTime, firTime );
                rs.next();
                String gysids = Util.null2String( rs.getString( 1 ) );
                if ("".equals( gysids )) {
                    zdcscs = zdcscs - 1;
                    String sql1 = "update uf_bidguestinfo set zdcscs=?,sycs=? where cglxd=?";
                    rs.executeUpdate( sql1, zdcscs, zdcscs, cglxd );
                } else {
                    String sql1 = "select wm_concat(gysid) from uf_bidguestinfo where cglxd=? and gysid not in (" + gysids + ")";
                    rs.executeQuery( sql1, cglxd );
                    rs.next();
                    String wbjgys = Util.null2String( rs.getString( 1 ) );
                    if (!"".equals( wbjgys )) {
                        zdcscs = zdcscs - 1;
                        String sql2 = "update uf_bidguestinfo set zdcscs=?,sycs=? where cglxd=? and gysid in (" + wbjgys + ")";
                        rs.executeUpdate( sql2, zdcscs, zdcscs, cglxd );
                    }
                }
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 获取供应商报价列表
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/queryGysbjData")
    @Produces({MediaType.TEXT_PLAIN})
    public String queryGysbjData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            JSONArray dataList = new JSONArray();
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                User user = HrmUserVarify.getUser( request, response );
                String loginid = user.getLoginid();
                String logintype = user.getLogintype();
                if ("1".equals( logintype )) {//主持人
                    String sql = "select rownum as xh,gysmc,dh,bj,ccbj,fdsz as fd,substr(rqsj,12) as sj from (\n" +
                            "select gysmc,dh,bj,ccbj,fdsz,rqsj from uf_bjxxb where cglxd=? order by rqsj desc)";
                    rs.executeQuery( sql, cglxd );
                    while (rs.next()) {
                        JSONObject dataMap = new JSONObject();
                        String xh = Util.null2String( rs.getString( "xh" ) );
                        String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                        String dh = Util.null2String( rs.getString( "dh" ) );
                        String bj = Util.null2String( rs.getString( "bj" ) );
                        String ccbj = Util.null2String( rs.getString( "ccbj" ) );
                        String fd = Util.null2String( rs.getString( "fd" ) );
                        String sj = Util.null2String( rs.getString( "sj" ) );
                        dataMap.put( "xh", xh );
                        dataMap.put( "gysmc", gysmc );
                        dataMap.put( "dh", dh );
                        dataMap.put( "bj", bj );
                        dataMap.put( "ccbj", ccbj );
                        dataMap.put( "fd", fd );
                        dataMap.put( "sj", sj );
                        dataList.add( dataMap );
                    }
                } else {//供应商
                    String sql = "select row_number() over( order by sj desc) xh,gysmc,dh,bj,ccbj,fd,sj from (\n" +
                            "select jmgysmc as gysmc,jmdh as dh,jmbj as bj,jmccbj as ccbj,jmfd as fd,substr(rqsj,12)as sj from (\n" +
                            "select jmgysmc,jmdh,jmbj,jmccbj,jmfd,rqsj from uf_bjxxb where cglxd=? and gysid!=? )\n" +
                            "union all\n" +
                            "select gysmc,dh,to_char(bj),to_char(ccbj),to_char(fdsz) as fd,substr(rqsj,12) as sj from (\n" +
                            "select gysmc,dh,bj,ccbj,fdsz,rqsj from uf_bjxxb where cglxd=? and gysid=? ))";
                    rs.executeQuery( sql, cglxd, loginid, cglxd, loginid );
                    while (rs.next()) {
                        JSONObject dataMap = new JSONObject();
                        String xh = Util.null2String( rs.getString( "xh" ) );
                        String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                        String dh = Util.null2String( rs.getString( "dh" ) );
                        String bj = Util.null2String( rs.getString( "bj" ) );
                        String ccbj = Util.null2String( rs.getString( "ccbj" ) );
                        String fd = Util.null2String( rs.getString( "fd" ) );
                        String sj = Util.null2String( rs.getString( "sj" ) );
                        dataMap.put( "xh", xh );
                        dataMap.put( "dh", dh );
                        dataMap.put( "gysmc", gysmc );
                        dataMap.put( "bj", bj );
                        dataMap.put( "ccbj", ccbj );
                        dataMap.put( "fd", fd );
                        dataMap.put( "sj", sj );
                        dataList.add( dataMap );
                    }
                }
                datas.put( "dataList", dataList );
                apidatas.put( "datas", datas );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单获取报价、时间
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getPriceAndTime")
    @Produces({MediaType.TEXT_PLAIN})
    public String getPriceAndTime(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject chartData = new JSONObject();
            JSONArray columns = new JSONArray();
            columns.add( "dateTime" );
            columns.add( "price" );
            JSONArray rows = new JSONArray();
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                rs.executeQuery( "select rqsj,bj from uf_bjxxb where cglxd=? order by rqsj", cglxd );
                while (rs.next()) {
                    JSONObject dataMap = new JSONObject();
                    String rqsj = Util.null2String( rs.getString( "rqsj" ) );
                    String bj = Util.null2String( rs.getString( "bj" ) );
                    dataMap.put( "dateTime", rqsj );
                    dataMap.put( "price", bj );
                    rows.add( dataMap );
                }
                chartData.put( "columns", columns );
                chartData.put( "rows", rows );
                apidatas.put( "chartData", chartData );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单获取采购竞价排名
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getCgPriceRank")
    @Produces({MediaType.TEXT_PLAIN})
    public String getCgPriceRank(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            JSONArray items = new JSONArray();
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                User user = HrmUserVarify.getUser( request, response );
                String loginid = user.getLoginid();
                String logintype = user.getLogintype();
                String jjgc = Util.null2String( request.getParameter( "jjgc" ) );//竞价过程
                rs.writeLog( "cglxd=" + cglxd + ",logintype=" + logintype + ",loginid=" + loginid + ",jjgc=" + jjgc );
                if ("1".equals( logintype )) {//主持人
                    String sql = "select rank() over (order by zxbj asc) pm,gysmc,dh,zxbj,bjcs from uf_bidguestinfo where cglxd=? and bjcs>0";
                    rs.executeQuery( sql, cglxd );
                    while (rs.next()) {
                        JSONObject dataMap = new JSONObject();
                        String pm = Util.null2String( rs.getString( "pm" ) );
                        String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                        String dh = Util.null2String( rs.getString( "dh" ) );
                        String zxbj = Util.null2String( rs.getString( "zxbj" ) );
                        String bjcs = Util.null2String( rs.getString( "bjcs" ) );
                        dataMap.put( "rank", "第" + pm + "名" );
                        dataMap.put( "name", gysmc );
                        dataMap.put( "code", dh );
                        dataMap.put( "amount", "￥" + zxbj );
                        dataMap.put( "times", "第" + bjcs + "次" );
                        items.add( dataMap );
                    }
                } else {//供应商
                    String sql = "";
                    switch (jjgc) {
                        case "0"://公开竞价公司：公司名称、排名是可见的价格是*** 号
                            sql = "select rank() over (order by zxbj1 asc) pm,gysmc,dh,zxbj,bjcs from (\n" +
                                    "select gysmc,dh,bjcs,jmzxbj as zxbj,zxbj as zxbj1 from uf_bidguestinfo where cglxd=? and bjcs>0)";
                            rs.executeQuery( sql, cglxd );
                            rs.writeLog( "sql=" + sql );
                            while (rs.next()) {
                                JSONObject dataMap = new JSONObject();
                                String pm = Util.null2String( rs.getString( "pm" ) );
                                String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                                String dh = Util.null2String( rs.getString( "dh" ) );
                                String zxbj = Util.null2String( rs.getString( "zxbj" ) );
                                String bjcs = Util.null2String( rs.getString( "bjcs" ) );
                                dataMap.put( "rank", "第" + pm + "名" );
                                dataMap.put( "name", gysmc );
                                dataMap.put( "code", dh );
                                dataMap.put( "amount", "￥" + zxbj );
                                dataMap.put( "times", "第" + bjcs + "次" );
                                items.add( dataMap );
                            }
                            break;
                        case "1"://公开竞价价格：价格、排名是可见的 公司名称是****
                            sql = "select rank() over (order by zxbj1 asc) pm,gysmc,dh,zxbj,bjcs from (\n" +
                                    "select jmgysmc as gysmc,jmdh as dh,bjcs,zxbj,zxbj as zxbj1 from uf_bidguestinfo where cglxd=? and bjcs>0)";
                            rs.executeQuery( sql, cglxd );
                            rs.writeLog( "sql=" + sql );
                            while (rs.next()) {
                                JSONObject dataMap = new JSONObject();
                                String pm = Util.null2String( rs.getString( "pm" ) );
                                String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                                String dh = Util.null2String( rs.getString( "dh" ) );
                                String zxbj = Util.null2String( rs.getString( "zxbj" ) );
                                String bjcs = Util.null2String( rs.getString( "bjcs" ) );
                                dataMap.put( "rank", "第" + pm + "名" );
                                dataMap.put( "name", gysmc );
                                dataMap.put( "code", dh );
                                dataMap.put( "amount", "￥" + zxbj );
                                dataMap.put( "times", "第" + bjcs + "次" );
                                items.add( dataMap );
                            }
                            break;
                        case "2"://隐藏竞标对手：其他供应商的都是*** 号或代码显示
                            sql = "select rank() over (order by zxbj1 asc) pm,gysmc,dh,zxbj,bjcs from (\n" +
                                    "select gysmc,dh,bjcs,zxbj,zxbj as zxbj1 from uf_bidguestinfo where cglxd=? and gysid =? and bjcs>0\n" +
                                    "union all\n" +
                                    "select jmgysmc,jmdh,bjcs,jmzxbj,zxbj as zxbj1 from uf_bidguestinfo where cglxd=? and gysid !=? and bjcs>0)";
                            rs.executeQuery( sql, cglxd, loginid, cglxd, loginid );
                            rs.writeLog( "sql=" + sql );
                            while (rs.next()) {
                                JSONObject dataMap = new JSONObject();
                                String pm = Util.null2String( rs.getString( "pm" ) );
                                String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                                String dh = Util.null2String( rs.getString( "dh" ) );
                                String zxbj = Util.null2String( rs.getString( "zxbj" ) );
                                String bjcs = Util.null2String( rs.getString( "bjcs" ) );
                                dataMap.put( "rank", "第" + pm + "名" );
                                dataMap.put( "name", gysmc );
                                dataMap.put( "code", dh );
                                dataMap.put( "amount", "￥" + zxbj );
                                dataMap.put( "times", "第" + bjcs + "次" );
                                items.add( dataMap );
                            }
                            break;
                        case "3"://只可见自己：只能显示自己的报价信息其他供应商全部不显示出来包括**号
                            sql = "select rank() over (order by zxbj asc) pm,gysmc,dh,zxbj,bjcs from (\n" +
                                    "select gysmc,dh,bjcs,zxbj,zxbj as zxbj1 from uf_bidguestinfo where cglxd=? and gysid =? and bjcs>0)";
                            rs.executeQuery( sql, cglxd, loginid );
                            rs.writeLog( "sql=" + sql );
                            while (rs.next()) {
                                JSONObject dataMap = new JSONObject();
                                String pm = Util.null2String( rs.getString( "pm" ) );
                                String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                                String dh = Util.null2String( rs.getString( "dh" ) );
                                String zxbj = Util.null2String( rs.getString( "zxbj" ) );
                                String bjcs = Util.null2String( rs.getString( "bjcs" ) );
                                dataMap.put( "rank", "第" + pm + "名" );
                                dataMap.put( "name", gysmc );
                                dataMap.put( "code", dh );
                                dataMap.put( "amount", "￥" + zxbj );
                                dataMap.put( "times", "第" + bjcs + "次" );
                                items.add( dataMap );
                            }
                            break;

                    }
                    rs.writeLog( "items=" + items );

                }
                datas.put( "items", items );
                apidatas.put( "datas", datas );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单获取拍卖竞价排名
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getPmPriceRank")
    @Produces({MediaType.TEXT_PLAIN})
    public String getPmPriceRank(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            JSONArray items = new JSONArray();
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                User user = HrmUserVarify.getUser( request, response );
                String loginid = user.getLoginid();
                String logintype = user.getLogintype();
                String jjgc = Util.null2String( request.getParameter( "jjgc" ) );//竞价过程
                if ("1".equals( logintype )) {//主持人
                    String sql = "select rank() over (order by zxbj desc) pm,gysmc,dh,zxbj,bjcs from uf_bidguestinfo where cglxd=? and bjcs>0";
                    rs.executeQuery( sql, cglxd );
                    while (rs.next()) {
                        JSONObject dataMap = new JSONObject();
                        String pm = Util.null2String( rs.getString( "pm" ) );
                        String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                        String dh = Util.null2String( rs.getString( "dh" ) );
                        String zxbj = Util.null2String( rs.getString( "zxbj" ) );
                        String bjcs = Util.null2String( rs.getString( "bjcs" ) );
                        dataMap.put( "rank", "第" + pm + "名" );
                        dataMap.put( "name", gysmc );
                        dataMap.put( "code", dh );
                        dataMap.put( "amount", "￥" + zxbj );
                        dataMap.put( "times", "第" + bjcs + "次" );
                        items.add( dataMap );
                    }
                } else {//供应商
                    String sql = "";
                    switch (jjgc) {
                        case "0"://公开竞价公司：公司名称、排名是可见的价格是*** 号
                            sql = "select rank() over (order by zxbj1 desc) pm,gysmc,dh,zxbj,bjcs from (\n" +
                                    "select gysmc,dh,bjcs,jmzxbj as zxbj,zxbj as zxbj1 from uf_bidguestinfo where cglxd=? and bjcs>0)";
                            rs.executeQuery( sql, cglxd );
                            while (rs.next()) {
                                JSONObject dataMap = new JSONObject();
                                String pm = Util.null2String( rs.getString( "pm" ) );
                                String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                                String dh = Util.null2String( rs.getString( "dh" ) );
                                String zxbj = Util.null2String( rs.getString( "zxbj" ) );
                                String bjcs = Util.null2String( rs.getString( "bjcs" ) );
                                dataMap.put( "rank", "第" + pm + "名" );
                                dataMap.put( "name", gysmc );
                                dataMap.put( "code", dh );
                                dataMap.put( "amount", "￥" + zxbj );
                                dataMap.put( "times", "第" + bjcs + "次" );
                                items.add( dataMap );
                            }
                            break;
                        case "1"://公开竞价价格：价格、排名是可见的 公司名称是****
                            sql = "select rank() over (order by zxbj1 desc) pm,gysmc,dh,zxbj,bjcs from (\n" +
                                    "select jmgysmc as gysmc,jmdh as dh,bjcs,zxbj,zxbj as zxbj1 from uf_bidguestinfo where cglxd=? and bjcs>0)";
                            rs.executeQuery( sql, cglxd );
                            while (rs.next()) {
                                JSONObject dataMap = new JSONObject();
                                String pm = Util.null2String( rs.getString( "pm" ) );
                                String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                                String dh = Util.null2String( rs.getString( "dh" ) );
                                String zxbj = Util.null2String( rs.getString( "zxbj" ) );
                                String bjcs = Util.null2String( rs.getString( "bjcs" ) );
                                dataMap.put( "rank", "第" + pm + "名" );
                                dataMap.put( "name", gysmc );
                                dataMap.put( "code", dh );
                                dataMap.put( "amount", "￥" + zxbj );
                                dataMap.put( "times", "第" + bjcs + "次" );
                                items.add( dataMap );
                            }
                            break;
                        case "2"://隐藏竞标对手：其他供应商的都是*** 号或代码显示
                            sql = "select rank() over (order by zxbj1 desc) pm,gysmc,dh,zxbj,bjcs from (\n" +
                                    "select gysmc,dh,bjcs,zxbj,zxbj as zxbj1 from uf_bidguestinfo where cglxd=? and gysid =? and bjcs>0\n" +
                                    "union all\n" +
                                    "select jmgysmc,jmdh,bjcs,jmzxbj,zxbj as zxbj1 from uf_bidguestinfo where cglxd=? and gysid !=? and bjcs>0)";
                            rs.executeQuery( sql, cglxd, loginid, cglxd, loginid );
                            while (rs.next()) {
                                JSONObject dataMap = new JSONObject();
                                String pm = Util.null2String( rs.getString( "pm" ) );
                                String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                                String dh = Util.null2String( rs.getString( "dh" ) );
                                String zxbj = Util.null2String( rs.getString( "zxbj" ) );
                                String bjcs = Util.null2String( rs.getString( "bjcs" ) );
                                dataMap.put( "rank", "第" + pm + "名" );
                                dataMap.put( "name", gysmc );
                                dataMap.put( "code", dh );
                                dataMap.put( "amount", "￥" + zxbj );
                                dataMap.put( "times", "第" + bjcs + "次" );
                                items.add( dataMap );
                            }
                            break;
                        case "3"://只可见自己：只能显示自己的报价信息其他供应商全部不显示出来包括**号
                            sql = "select rank() over (order by zxbj desc) pm,gysmc,dh,zxbj,bjcs from (\n" +
                                    "select gysmc,dh,bjcs,zxbj,zxbj as zxbj1 from uf_bidguestinfo where cglxd=? and gysid =? and bjcs>0)";
                            rs.executeQuery( sql, cglxd, loginid );
                            while (rs.next()) {
                                JSONObject dataMap = new JSONObject();
                                String pm = Util.null2String( rs.getString( "pm" ) );
                                String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                                String dh = Util.null2String( rs.getString( "dh" ) );
                                String zxbj = Util.null2String( rs.getString( "zxbj" ) );
                                String bjcs = Util.null2String( rs.getString( "bjcs" ) );
                                dataMap.put( "rank", "第" + pm + "名" );
                                dataMap.put( "name", gysmc );
                                dataMap.put( "code", dh );
                                dataMap.put( "amount", "￥" + zxbj );
                                dataMap.put( "times", "第" + bjcs + "次" );
                                items.add( dataMap );
                            }
                            break;

                    }
                    rs.writeLog( "sql=" + sql );
                    rs.writeLog( "items=" + items );
                }
                datas.put( "items", items );
                apidatas.put( "datas", datas );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据loginID获取供应商名称
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getLoginId2Name")
    @Produces({MediaType.TEXT_PLAIN})
    public String getLoginId2Name(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                User user = HrmUserVarify.getUser( request, response );
                String username = user.getUsername();
                String loginid = user.getLoginid();
                String logintype = user.getLogintype();
                String cglxmc = GenUtil.getCglxd2Name( cglxd );
                datas.put( "loginid", loginid );
                datas.put( "logintype", logintype );
                datas.put( "username", username );
                datas.put( "cglxmc", cglxmc );
                apidatas.put( "datas", datas );
                apidatas.put( "api_status", true );
            } else {
                apidatas.put( "api_status", false );
            }

        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单动态获取参与竞价的供应商数
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getGysCounts")
    @Produces({MediaType.TEXT_PLAIN})
    public String getGysCounts(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                String sql = "select count(gysid) as counts from (\n" +
                        "select gysid from uf_bjxxb where cglxd=? group by gysid)";
                rs.executeQuery( sql, cglxd );
                rs.next();
                int counts = Util.getIntValue( rs.getString( "counts" ) );
                datas.put( "counts", counts );
                apidatas.put( "datas", datas );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单获取公布结果
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getPublishResult")
    @Produces({MediaType.TEXT_PLAIN})
    public String getPublishResult(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                String billid = "";
                String sql = "select id from uf_gbjg where cglxd=?";
                rs.executeQuery( sql, cglxd );
                if(rs.next()){
                    billid = Util.null2String(rs.getString("id"));
                }
                datas.put( "billid", billid );
                apidatas.put( "datas", datas );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单更新竞价信息表字段
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getUpdateBidInfo")
    @Produces({MediaType.TEXT_PLAIN})
    public String getUpdateBidInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                int jjszParm = Util.getIntValue( request.getParameter( "jjsz" ) );
                int jbyqParm = Util.getIntValue( request.getParameter( "jbyq" ) );
                int ksjjParm = Util.getIntValue( request.getParameter( "ksjj" ) );
                int gbjgParm = Util.getIntValue( request.getParameter( "gbjg" ) );
                int ljbjParm = Util.getIntValue( request.getParameter( "ljbj" ) );
                int dqztParm = Util.getIntValue( request.getParameter( "dqzt" ) );
                int djsszParm = Util.getIntValue( request.getParameter( "djssz" ) );
                String sql = "update uf_biddinginfo set jjsz=?,jbyq=?,ksjj=?,gbjg=?,ljbj=?,dqzt=?,djssz=? where cglxd=?";
                Object[] params = {jjszParm, jbyqParm, ksjjParm, gbjgParm, ljbjParm, dqztParm, djsszParm, cglxd};
                rs.executeUpdate( sql, params );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单更新竞价信息表字段
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/updateLjbjBtn")
    @Produces({MediaType.TEXT_PLAIN})
    public String updateLjbjBtn(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                RecordSet rs1 = new RecordSet();
                String sql = "update uf_biddinginfo set ljbj=0 where cglxd=?";
                if (rs.executeUpdate( sql, cglxd )) {
                    String sql1 = "select ljbj from uf_biddinginfo where cglxd=?";
                    rs1.executeQuery( sql1, cglxd );
                    rs1.next();
                    String ljbj = Util.null2String( rs1.getString( "ljbj" ) );//立即报价
                    datas.put( "ljbjBtnDispaly", GenUtil.getNum2Bool( ljbj ) );
                    apidatas.put( "datas", datas );
                    apidatas.put( "api_status", true );
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 获取报价信息表中的按钮状态，当前状态
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getBidStatus")
    @Produces({MediaType.TEXT_PLAIN})
    public String getBidStatus(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                rs.executeQuery( "select jjsz,jbyq,ksjj,gbjg,ljbj,dqzt,djssz from uf_biddinginfo where cglxd=?", cglxd );
                rs.next();
                String jjsz = Util.null2String( rs.getString( "jjsz" ) );//竞价设置
                String jbyq = Util.null2String( rs.getString( "jbyq" ) );//嘉宾邀请
                String ksjj = Util.null2String( rs.getString( "ksjj" ) );//开始竞价
                String gbjg = Util.null2String( rs.getString( "gbjg" ) );//公布结果
                String ljbj = Util.null2String( rs.getString( "ljbj" ) );//立即报价
                String dqzt = Util.null2String( rs.getString( "dqzt" ) );//当前状态
                String dqztmc = GenUtil.getSelectItem( 1141, "dqzt", dqzt + "" );//当前状态名称
                String djssz = Util.null2String( rs.getString( "djssz" ) );//倒计时设置
                datas.put( "szbtnDisplay", GenUtil.getNum2Bool( jjsz ) );
                datas.put( "yqbtnDisplay", GenUtil.getNum2Bool( jbyq ) );
                datas.put( "ksbtnDisplay", GenUtil.getNum2Bool( ksjj ) );
                datas.put( "jgbtnDisplay", GenUtil.getNum2Bool( gbjg ) );
                datas.put( "ljbjBtnDispaly", GenUtil.getNum2Bool( ljbj ) );
                datas.put( "setCountDown", djssz );
                datas.put( "curstatus", dqztmc );
                apidatas.put( "datas", datas );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 获取当前状态是否结束
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getSetCountDown")
    @Produces({MediaType.TEXT_PLAIN})
    public String getSetCountDown(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                rs.executeQuery( "select djssz,jjscsj,jjkssj,sljjsj,jjyssj from uf_biddinginfo where cglxd=?", cglxd );
                rs.next();
                String djssz = Util.null2String( rs.getString( "djssz" ) );//倒计时设置
                String jjkssj = Util.null2String( rs.getString( "jjkssj" ) );//竞价开始时间
                String jjscsj = Util.null2String( rs.getString( "jjscsj" ) );//竞价时长时间
                String sljjsj = Util.null2String( rs.getString( "sljjsj" ) );//	首轮竞价时间
                String jjyssj = Util.null2String( rs.getString( "jjyssj" ) );//	竞价延迟时间
                apidatas.put( "staTime", jjkssj );
                apidatas.put( "firTime", sljjsj );
                apidatas.put( "endTime", jjscsj );
                apidatas.put( "delTime", jjyssj );
                apidatas.put( "setCountDown", djssz );
                rs.executeQuery( "select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') as curtime from dual" );
                rs.next();
                String curtime = Util.null2String( rs.getString( "curtime" ) );//当前时间
                apidatas.put( "curtime", curtime );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 插入分钟倒计时
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/insertBidTime")
    @Produces({MediaType.TEXT_PLAIN})
    public String insertBidTime(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                int slsc = Util.getIntValue( request.getParameter( "slsc" ) );//首轮时长
                int jjsc = Util.getIntValue( request.getParameter( "jjsc" ) );//竞价时长
                int jjys = Util.getIntValue( request.getParameter( "jjys" ) );//竞价延时
                jjys = jjsc * 60 + jjys;
                String sql = "merge into uf_biddinginfo a USING (select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') as statime,\n" +
                        "to_char(sysdate + interval '" + slsc + "' MINUTE,'yyyy-MM-dd HH24:mi:ss') as firtime,\n" +
                        "to_char(sysdate + interval '" + jjsc + "' MINUTE,'yyyy-MM-dd HH24:mi:ss') as endtime,\n" +
                        "to_char(sysdate + interval '" + jjys + "' SECOND,'yyyy-MM-dd HH24:mi:ss') as deltime\n" +
                        "from dual) C ON(a.cglxd=" + cglxd + ")\n" +
                        "WHEN MATCHED THEN\n" +
                        "UPDATE SET a.jjkssj=c.statime,a.sljjsj=c.firtime,a.jjscsj=c.endtime,a.jjyssj=c.deltime";
                rs.executeUpdate( sql );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单、loginid获取上次报价
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getNowBidPirce")
    @Produces({MediaType.TEXT_PLAIN})
    public String getNowBidPirce(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                User user = HrmUserVarify.getUser( request, response );
                String loginid = user.getLoginid();
                String sql = "select nvl(sum(bj),0) from (\n" +
                        "select row_number() over( order by rqsj desc) rn,bj from uf_bjxxb where cglxd=? and gysid=? order by rqsj desc)where rn = 1";
                rs.executeQuery( sql, cglxd, loginid );
                rs.next();
                String lastQuote = Util.null2String( rs.getString( 1 ) );//上次报价
                datas.put( "lastQuote", lastQuote );

                String sql1 = "select zdcscs from uf_bidguestinfo where cglxd=? and gysid=?";
                rs.executeQuery( sql1, cglxd, loginid );
                rs.next();
                String quoteTimes = Util.null2String( rs.getString( 1 ) );//最大报价次数
                datas.put( "quoteTimes", quoteTimes );

                String sql2 = "select count(id) from uf_bjxxb where cglxd=? and gysid=?";
                rs.executeQuery( sql2, cglxd, loginid );
                rs.next();
                String newsTimes = Util.null2String( rs.getString( 1 ) );//最新报价次数
                datas.put( "newsTimes", newsTimes );

                String sql3 = "select nvl(max(bj),0) from uf_bjxxb where cglxd=?";
                rs.executeQuery( sql3, cglxd );
                rs.next();
                String maxPrice = Util.null2String( rs.getString( 1 ) );//全场最高价
                datas.put( "maxPrice", maxPrice );

                apidatas.put( "datas", datas );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单重置延时倒计时
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/resetDelTime")
    @Produces({MediaType.TEXT_PLAIN})
    public String resetDelTime(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                String jjys = Util.null2String( request.getParameter( "jjys" ) );//竞价延时
                String bjcs = Util.null2String( request.getParameter( "bjcs" ) );//报价次数
                String delTime = "";
                String sql = "merge into uf_biddinginfo a USING (select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') as ljbjtime,\n" +
                        "to_char(sysdate + interval '" + jjys + "' SECOND,'yyyy-MM-dd HH24:mi:ss') as deltime\n" +
                        "from dual) C ON(a.cglxd=?)WHEN MATCHED THEN UPDATE SET a.jjyssj=c.deltime,a.ljbjsj=c.ljbjtime,a.bjcs=?";
                rs.executeUpdate( sql, cglxd, bjcs );
                apidatas.put( "delTime", delTime );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 获取秒针倒计时
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getLjbjTimes")
    @Produces({MediaType.TEXT_PLAIN})
    public String getLjbjTimes(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                rs.executeQuery( "select ljbjsj,bjcs from uf_biddinginfo where cglxd=?", cglxd );
                rs.next();
                String ljbjsj = Util.null2String( rs.getString( "ljbjsj" ) );
                String ljbjbjcs = Util.null2String( rs.getString( "bjcs" ) );
                apidatas.put( "ljbjtime", ljbjsj );
                apidatas.put( "ljbjbjcs", ljbjbjcs );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 更新立即报价按钮状态
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/updateLjbjTimes")
    @Produces({MediaType.TEXT_PLAIN})
    public String updateLjbjTimes(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                String sql = "update uf_biddinginfo set bjcs=0 where cglxd=? ";
                rs.executeUpdate( sql, cglxd );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 更新报价次数到报价信息中
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/updateBidTimes")
    @Produces({MediaType.TEXT_PLAIN})
    public String updateBidTimes(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            RecordSet rs = new RecordSet();
            String cglxdBase64 = Util.null2String( request.getParameter( "cglxdBase64" ) );
            rs.writeLog( "cglxdBase64="+cglxdBase64 );
            if (!"".equals( cglxdBase64 )) {
                String cglxd = Base64Util.decode( cglxdBase64 );
                rs.writeLog( "cglxd="+cglxd );
                int zdcscs = Util.getIntValue( request.getParameter( "zdcscs" ) );//最大出手次数
                String rqsj = DateUtil.getFullDate();//时间
                String sql = "update uf_bidguestinfo set zdcscs=?,sycs=?,rqsj=? where cglxd=?";
                Object[] params = {zdcscs, zdcscs, rqsj, cglxd,};
                rs.executeUpdate( sql, params );
                apidatas.put( "api_status", true );
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

}
